//
//  Utility.m
//  test
//
//  Created by 朱圳 on 2018/1/9.
//  Copyright © 2018年 朱圳. All rights reserved.
//

#import "Utility.h"

@implementation Utility

+(void)showSuccess:(NSString *)msg{
    
    UIView *window = [[UIApplication sharedApplication].delegate window];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
    
    hud.mode = MBProgressHUDModeCustomView;
//    hud.customView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"yes"]];
    hud.labelText = msg;
    
    hud.color=[UIColor lightGrayColor];
    
    
    [hud hide:YES afterDelay:1.0];
    
}

+(void)showFail:(NSString *)msg{
    UIView *window = [[UIApplication sharedApplication].delegate window];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
    
    hud.mode = MBProgressHUDModeText;
  //  hud.customView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"no"]];
    hud.color = [UIColor redColor];
    hud.detailsLabelText = msg;
    hud.labelFont = [UIFont systemFontOfSize:14];
    [hud hide:YES afterDelay:1.0];

}

// 时间转时间戳,时间戳为13位是精确到毫秒的，10位精确到秒
+ (NSString *)getTimeStrWithString:(NSString *)str{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];// 创建一个时间格式化对象
    [dateFormatter setDateFormat:@"yyyyMMdd HH:mm"]; //设定时间的格式
    NSDate *tempDate = [dateFormatter dateFromString:str];//将字符串转换为时间对象
    NSString *timeStr = [NSString stringWithFormat:@"%ld", (long)[tempDate timeIntervalSince1970]];//字符串转成时间戳
    return timeStr;
}
// 时间戳转时间,时间戳为13位是精确到毫秒的，10位精确到秒
+ (NSString *)getDateStringWithTimeStr:(NSString *)str{
    NSTimeInterval time=[str doubleValue];//传入的时间戳str如果是精确到毫秒的记得要/1000
    NSDate *detailDate=[NSDate dateWithTimeIntervalSince1970:time];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; //实例化一个NSDateFormatter对象
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *currentDateStr = [dateFormatter stringFromDate: detailDate];
    return currentDateStr;
}
@end
